# PRIV_CONFIG_GEN_BLE is and should only be defined in bouffalo.mk in the 'blecontroller_*' component
# ifeq ($(CONFIG_CHIP_NAME),BL702)
# PRIV_CONFIG_GEN_BLE ?= $(CONFIG_BLECONTROLLER_LIB)
# else ifeq ($(CONFIG_CHIP_NAME),BL602)
# PRIV_CONFIG_GEN_BLE ?= $(CONFIG_BLECONTROLLER_LIB)
# else
# PRIV_CONFIG_GEN_BLE ?= $(CONFIG_BTBLECONTROLLER_LIB)
# endif
if("${CHIP}" STREQUAL "bl702")
	sdk_ifndef(PRIV_CONFIG_GEN_BLE ${CONFIG_BLECONTROLLER_LIB})
elseif("${CHIP}" STREQUAL "bl602")
	sdk_ifndef(PRIV_CONFIG_GEN_BLE ${CONFIG_BLECONTROLLER_LIB})
else()
	sdk_ifndef(PRIV_CONFIG_GEN_BLE ${CONFIG_BTBLECONTROLLER_LIB})
endif()

# ifeq ($(PRIV_CONFIG_GEN_BLE),std)
# CONFIG_BLE_TP_SERVER := 1
# endif
if("${PRIV_CONFIG_GEN_BLE}" STREQUAL "std")
	set(CONFIG_BLE_TP_SERVER 1)

# ifeq ($(PRIV_CONFIG_GEN_BLE),m0s1)
# CONFIG_BT_CONN := 1
# CONFIG_BLE_TX_BUFF_DATA := 2
# CONFIG_BT_MESH := 0
# CONFIG_BT_ALLROLES := 0
# CONFIG_BT_CENTRAL := 0
# CONFIG_BT_PERIPHERAL := 1
# CONFIG_BT_OBSERVER := 0
# CONFIG_BT_BROADCASTER := 0
# CONFIG_DISABLE_BT_SMP := 1
# CONFIG_DISABLE_BT_HOST_PRIVACY := 1
# CONFIG_DISABLE_BT_ECC := 1
# CONFIG_DISABLE_BLE_CONTROLLER_PHY_UPDATE := 1
# CONFIG_DISABLE_BLE_CONTROLLER_TEST_MODE := 1
# CONFIG_DISABLE_BLE_CONTROLLER_SEC_CON := 1
# endif
elseif("${PRIV_CONFIG_GEN_BLE}" STREQUAL "m0s1")
	set(CONFIG_BT_CONN 1)
	set(CONFIG_BLE_TX_BUFF_DATA 2)
	set(CONFIG_BT_MESH 0)
	set(CONFIG_BT_ALLROLES 0)
	set(CONFIG_BT_CENTRAL 0)
	set(CONFIG_BT_PERIPHERAL 1)
	set(CONFIG_BT_OBSERVER 0)
	set(CONFIG_BT_BROADCASTER 0)
	set(CONFIG_DISABLE_BT_SMP 1)
	set(CONFIG_DISABLE_BT_HOST_PRIVACY 1)
	set(CONFIG_DISABLE_BT_ECC 1)
	set(CONFIG_DISABLE_BLE_CONTROLLER_PHY_UPDATE 1)
	set(CONFIG_DISABLE_BLE_CONTROLLER_TEST_MODE 1)
	set(CONFIG_DISABLE_BLE_CONTROLLER_SEC_CON 1)

# ifeq ($(PRIV_CONFIG_GEN_BLE),m0s1s)
# CONFIG_BT_CONN := 1
# CONFIG_BLE_TX_BUFF_DATA := 2
# CONFIG_BT_MESH := 0
# CONFIG_BT_ALLROLES := 0
# CONFIG_BT_CENTRAL := 0
# CONFIG_BT_PERIPHERAL := 1
# CONFIG_BT_OBSERVER := 1
# CONFIG_BT_BROADCASTER := 0
# CONFIG_DISABLE_BT_SMP := 1
# CONFIG_DISABLE_BT_HOST_PRIVACY := 1
# CONFIG_DISABLE_BT_ECC := 1
# CONFIG_DISABLE_BLE_CONTROLLER_PHY_UPDATE := 1
# CONFIG_DISABLE_BLE_CONTROLLER_TEST_MODE := 1
# CONFIG_DISABLE_BLE_CONTROLLER_SEC_CON := 1
# endif
elseif("${PRIV_CONFIG_GEN_BLE}" STREQUAL "m0s1s")
	set(CONFIG_BT_CONN 1)
	set(CONFIG_BLE_TX_BUFF_DATA 2)
	set(CONFIG_BT_MESH 0)
	set(CONFIG_BT_ALLROLES 0)
	set(CONFIG_BT_CENTRAL 0)
	set(CONFIG_BT_PERIPHERAL 1)
	set(CONFIG_BT_OBSERVER 1)
	set(CONFIG_BT_BROADCASTER 0)
	set(CONFIG_DISABLE_BT_SMP 1)
	set(CONFIG_DISABLE_BT_HOST_PRIVACY 1)
	set(CONFIG_DISABLE_BT_ECC 1)
	set(CONFIG_DISABLE_BLE_CONTROLLER_PHY_UPDATE 1)
	set(CONFIG_DISABLE_BLE_CONTROLLER_TEST_MODE 1)
	set(CONFIG_DISABLE_BLE_CONTROLLER_SEC_CON 1)

# ifeq ($(PRIV_CONFIG_GEN_BLE),m0s1p)
# CONFIG_BLE_PDS := 1
# CONFIG_BT_CONN := 1
# CONFIG_BLE_TX_BUFF_DATA := 2
# CONFIG_BT_MESH := 0
# CONFIG_BT_ALLROLES := 0
# CONFIG_BT_CENTRAL := 0
# CONFIG_BT_PERIPHERAL := 1
# CONFIG_BT_OBSERVER := 0
# CONFIG_BT_BROADCASTER := 0
# CONFIG_DISABLE_BT_SMP := 1
# CONFIG_DISABLE_BT_HOST_PRIVACY := 1
# CONFIG_BT_GATT_CLIENT := 0
# CONFIG_DISABLE_BLE_CONTROLLER_TEST_MODE := 1
# CONFIG_BT_STACK_CLI := 0
# endif
elseif("${PRIV_CONFIG_GEN_BLE}" STREQUAL "m0s1p")
	set(CONFIG_BLE_PDS 1)
	set(CONFIG_BT_CONN 0)
	set(CONFIG_BLE_TX_BUFF_DATA 2)
	set(CONFIG_BT_MESH 0)
	set(CONFIG_BT_ALLROLES 0)
	set(CONFIG_BT_CENTRAL 0)
	set(CONFIG_BT_PERIPHERAL 1)
	set(CONFIG_BT_OBSERVER 0)
	set(CONFIG_BT_BROADCASTER 0)
	set(CONFIG_DISABLE_BT_SMP 1)
	set(CONFIG_DISABLE_BT_HOST_PRIVACY 1)
	set(CONFIG_BT_STACK_CLI 0)

# ifeq ($(PRIV_CONFIG_GEN_BLE),m0s0sp)
# CONFIG_BLE_PDS := 1
# CONFIG_BT_CONN := 0
# CONFIG_BLE_TX_BUFF_DATA := 2
# CONFIG_BT_MESH := 0
# CONFIG_BT_ALLROLES := 0
# CONFIG_BT_CENTRAL := 0
# CONFIG_BT_PERIPHERAL := 0
# CONFIG_BT_OBSERVER := 1
# CONFIG_BT_BROADCASTER := 0
# CONFIG_DISABLE_BT_SMP := 1
# CONFIG_DISABLE_BT_HOST_PRIVACY := 1
# CONFIG_BT_STACK_CLI := 0
# endif
elseif("${PRIV_CONFIG_GEN_BLE}" STREQUAL "m0s0sp")
	set(CONFIG_BLE_PDS 1)
	set(CONFIG_BT_CONN 0)
	set(CONFIG_BLE_TX_BUFF_DATA 2)
	set(CONFIG_BT_MESH 0)
	set(CONFIG_BT_ALLROLES 0)
	set(CONFIG_BT_CENTRAL 0)
	set(CONFIG_BT_PERIPHERAL 0)
	set(CONFIG_BT_OBSERVER 1)
	set(CONFIG_BT_BROADCASTER 0)
	set(CONFIG_DISABLE_BT_SMP 1)
	set(CONFIG_DISABLE_BT_HOST_PRIVACY 1)
	set(CONFIG_BT_STACK_CLI 0)

#ifeq ($(PRIV_CONFIG_GEN_BLE),m16s1)
#CONFIG_BT_CONN := 16
#CONFIG_BT_ALLROLES := 0
#CONFIG_BT_CENTRAL := 1
#CONFIG_BT_PERIPHERAL := 1
#CONFIG_BT_OBSERVER := 1
#CONFIG_BT_BROADCASTER := 0
#CONFIG_BLE_STACK_DBG_PRINT := 0
#CONFIG_DISABLE_BT_SMP := 1
#CONFIG_BT_GATT_CLIENT := 0
#CONFIG_SIMPLE_MASTER := 1
#CONFIG_EM_16K := 1
#endif
elseif("${PRIV_CONFIG_GEN_BLE}" STREQUAL "m16s1")
	set(CONFIG_BT_CONN 16)
	set(CONFIG_BT_ALLROLES 0)
	set(CONFIG_BT_CENTRAL 1)
	set(CONFIG_BT_PERIPHERAL 1)
	set(CONFIG_BT_OBSERVER 1)
	set(CONFIG_BT_BROADCASTER 0)
	set(CONFIG_BLE_STACK_DBG_PRINT 0)
	set(CONFIG_DISABLE_BT_SMP 1)
	set(CONFIG_BT_GATT_CLIENT 0)
	set(CONFIG_SIMPLE_MASTER 1)
	set(CONFIG_EM_16K 1)
endif()

# ifeq ($(CONFIG_CHIP_NAME),BL702L)
if("${CHIP}" STREQUAL "bl702l")
# CONFIG_BT := 0
# CONFIG_CIS := 0
# CONFIG_ADV_EXTENSION := 0
# CONFIG_BIS := 0
# CONFIG_LE_PWR_CTRL := 0
# CONFIG_CTE := 0
# CONFIG_EM_SIZE := 16
	set(CONFIG_BT 0)
	set(CONFIG_CIS 0)
	set(CONFIG_ADV_EXTENSION 0)
	set(CONFIG_BIS 0)
	set(CONFIG_LE_PWR_CTRL 0)
	set(CONFIG_CTE 0)
	set(CONFIG_EM_SIZE 16)

# ifeq ($(PRIV_CONFIG_GEN_BLE),m1s1)
# CONFIG_BT_CONN := 1
# CONFIG_BLE_ACT_MAX := 5
# CONFIG_BT_ALLROLES := 1
# CONFIG_DISABLE_BT_SMP := 1
# CONFIG_DISABLE_BT_HOST_PRIVACY := 1
# CONFIG_DISABLE_BT_ECC := 1
# CONFIG_DISABLE_BLE_CONTROLLER_TEST_MODE := 1
# CONFIG_DISABLE_BLE_CONTROLLER_SEC_CON := 1
# endif
	if("${PRIV_CONFIG_GEN_BLE}" STREQUAL "m1s1")
		set(CONFIG_BT_CONN 1)
		set(CONFIG_BLE_ACT_MAX 5)
		set(CONFIG_BT_ALLROLES 1)
		set(CONFIG_DISABLE_BT_SMP 1)
		set(CONFIG_DISABLE_BT_HOST_PRIVACY 1)
		set(CONFIG_DISABLE_BT_ECC 1)
		set(CONFIG_DISABLE_BLE_CONTROLLER_TEST_MODE 1)
		set(CONFIG_DISABLE_BLE_CONTROLLER_SEC_CON 1)

# ifeq ($(PRIV_CONFIG_GEN_BLE),m1s1p)
# CONFIG_BLE_PDS := 1
# CONFIG_BT_CONN := 1
# CONFIG_BLE_ACT_MAX := 5
# CONFIG_BT_ALLROLES := 1
# CONFIG_DISABLE_BT_SMP := 1
# CONFIG_DISABLE_BT_HOST_PRIVACY := 1
# CONFIG_DISABLE_BT_ECC := 1
# CONFIG_DISABLE_BLE_CONTROLLER_TEST_MODE := 1
# CONFIG_DISABLE_BLE_CONTROLLER_SEC_CON := 1
# endif
	elseif("${PRIV_CONFIG_GEN_BLE}" STREQUAL "m1s1p")
		set(CONFIG_BLE_PDS 1)
		set(CONFIG_BT_CONN 1)
		set(CONFIG_BLE_ACT_MAX 5)
		set(CONFIG_BT_ALLROLES 1)
		set(CONFIG_DISABLE_BT_SMP 1)
		set(CONFIG_DISABLE_BT_HOST_PRIVACY 1)
		set(CONFIG_DISABLE_BT_ECC 1)
		set(CONFIG_DISABLE_BLE_CONTROLLER_TEST_MODE 1)
		set(CONFIG_DISABLE_BLE_CONTROLLER_SEC_CON 1)

# ifeq ($(PRIV_CONFIG_GEN_BLE),m8s1)
# CONFIG_BUILD_ROM_CODE := 1
# CONFIG_BT_CONN := 8
# CONFIG_BLE_ACT_MAX := 9
# CONFIG_BT_ALLROLES := 1
# CONFIG_DISABLE_BT_SMP := 1
# CONFIG_DISABLE_BT_HOST_PRIVACY := 1
# CONFIG_DISABLE_BT_ECC := 1
# CONFIG_DISABLE_BLE_CONTROLLER_TEST_MODE := 1
# CONFIG_DISABLE_BLE_CONTROLLER_SEC_CON := 1
# endif
	elseif("${PRIV_CONFIG_GEN_BLE}" STREQUAL "m8s1")
		set(CONFIG_BUILD_ROM_CODE 1)
		set(CONFIG_BT_CONN 8)
		set(CONFIG_BLE_ACT_MAX 9)
		set(CONFIG_BT_ALLROLES 1)
		set(CONFIG_DISABLE_BT_SMP 1)
		set(CONFIG_DISABLE_BT_HOST_PRIVACY 1)
		set(CONFIG_DISABLE_BT_ECC 1)
		set(CONFIG_DISABLE_BLE_CONTROLLER_TEST_MODE 1)
		set(CONFIG_DISABLE_BLE_CONTROLLER_SEC_CON 1)
	endif()
# endif
endif()

# ifeq ($(CONFIG_CHIP_NAME),BL616)
if(("${CHIP}" STREQUAL "bl616") OR ("${CHIP}" STREQUAL "bl808"))
# ifeq ($(PRIV_CONFIG_GEN_BLE),ble1m0s1bredr0)
# CONFIG_BT_BREDR := 0
# CONFIG_EM_SIZE := 32
# CONFIG_BT_ALLROLES := 0
# CONFIG_BT_CENTRAL := 0
# CONFIG_BT_PERIPHERAL := 1
# CONFIG_BT_BROADCASTER := 1
# CONFIG_BT_OBSERVER := 0
# CONFIG_DISABLE_BLE_CONTROLLER_TEST_MODE := 1
# CONFIG_BT_CONN := 1
# CONFIG_BLE_TX_BUFF_DATA := 2
# CONFIG_BLE_ACT_MAX := 5
# CONFIG_DISABLE_BT_ECC := 1
# CONFIG_SEC_CONN := 0
# CONFIG_DISABLE_CONTROLLER_BLE_PRIVACY := 1
# CONFIG_ADV_EXTENSION := 0
# CONFIG_CIS := 0
# CONFIG_BIS := 0
# CONFIG_CTE := 0
# CONFIG_LE_PWR_CTRL := 0
# endif
    if("${PRIV_CONFIG_GEN_BLE}" STREQUAL "ble1m0s1bredr0")
		set(CONFIG_BT_BREDR 0)
		set(CONFIG_EM_SIZE 32)
		set(CONFIG_BT_ALLROLES 0)
		set(CONFIG_BT_CENTRAL 0)
		set(CONFIG_BT_PERIPHERAL 1)
		set(CONFIG_BT_BROADCASTER 1)
		set(CONFIG_BT_OBSERVER 0)
		set(CONFIG_DISABLE_BLE_CONTROLLER_TEST_MODE 1)
		set(CONFIG_BT_CONN 1)
		set(CONFIG_BLE_TX_BUFF_DATA 2)
		set(CONFIG_BLE_ACT_MAX 5)
		set(CONFIG_DISABLE_BT_ECC 1)
		set(CONFIG_SEC_CONN 0)
		set(CONFIG_DISABLE_CONTROLLER_BLE_PRIVACY 1)
		set(CONFIG_ADV_EXTENSION 0)
		set(CONFIG_CIS 0)
		set(CONFIG_BIS 0)
		set(CONFIG_CTE 0)
		set(CONFIG_LE_PWR_CTRL 0)
# ifeq ($(PRIV_CONFIG_GEN_BLE),ble1m10s1bredr0)
# CONFIG_BT_BREDR := 0
# CONFIG_EM_SIZE=32
# CONFIG_BT_ALLROLES := 1
# CONFIG_BT_CENTRAL := 1
# CONFIG_BT_PERIPHERAL := 1
# CONFIG_BT_BROADCASTER := 1
# CONFIG_BT_OBSERVER := 1
# CONFIG_DISABLE_BLE_CONTROLLER_TEST_MODE := 1
# CONFIG_BT_CONN := 10
# CONFIG_BLE_ACT_MAX := 11
# CONFIG_ADV_EXTENSION := 0
# CONFIG_CIS := 0
# CONFIG_BIS := 0
# CONFIG_CTE := 0
# CONFIG_LE_PWR_CTRL := 0
# endif
	elseif("${PRIV_CONFIG_GEN_BLE}" STREQUAL "ble1m10s1bredr0")
		set(CONFIG_BT_BREDR 0)
		set(CONFIG_EM_SIZE 32)
		set(CONFIG_BT_ALLROLES 1)
		set(CONFIG_BT_CENTRAL 1)
		set(CONFIG_BT_PERIPHERAL 1)
		set(CONFIG_BT_BROADCASTER 1)
		set(CONFIG_BT_OBSERVER 1)
		set(CONFIG_DISABLE_BLE_CONTROLLER_TEST_MODE 1)
		set(CONFIG_BT_CONN 10)
		set(CONFIG_BLE_ACT_MAX 11)
		set(CONFIG_ADV_EXTENSION 0)
		set(CONFIG_CIS 0)
		set(CONFIG_BIS 0)
		set(CONFIG_CTE 0)
		set(CONFIG_LE_PWR_CTRL 0)
# ifeq ($(PRIV_CONFIG_GEN_BLE),ble1m0s1sbredr0)
# CONFIG_BT_BREDR := 0
# CONFIG_EM_SIZE=32
# CONFIG_BT_ALLROLES := 0
# CONFIG_BT_CENTRAL := 0
# CONFIG_BT_PERIPHERAL := 1
# CONFIG_BT_BROADCASTER := 1
# CONFIG_BT_OBSERVER := 1
# CONFIG_DISABLE_BLE_CONTROLLER_TEST_MODE := 1
# CONFIG_BT_CONN := 1
# CONFIG_BLE_TX_BUFF_DATA := 2
# CONFIG_BLE_ACT_MAX := 5
# CONFIG_ADV_EXTENSION := 0
# CONFIG_CIS := 0
# CONFIG_BIS := 0
# CONFIG_CTE := 0
# CONFIG_LE_PWR_CTRL := 0
# endif
    elseif("${PRIV_CONFIG_GEN_BLE}" STREQUAL "ble1m0s1sbredr0")
		set(CONFIG_BT_BREDR 0)
		set(CONFIG_EM_SIZE 32)
		set(CONFIG_BT_ALLROLES 0)
		set(CONFIG_BT_CENTRAL 0)
		set(CONFIG_BT_PERIPHERAL 1)
		set(CONFIG_BT_BROADCASTER 1)
		set(CONFIG_BT_OBSERVER 1)
		set(CONFIG_DISABLE_BLE_CONTROLLER_TEST_MODE 1)
		set(CONFIG_BT_CONN 1)
		set(CONFIG_BLE_TX_BUFF_DATA 2)
		set(CONFIG_BLE_ACT_MAX 5)
		set(CONFIG_ADV_EXTENSION 0)
		set(CONFIG_CIS 0)
		set(CONFIG_BIS 0)
		set(CONFIG_CTE 0)
		set(CONFIG_LE_PWR_CTRL 0)

# ifeq ($(PRIV_CONFIG_GEN_BLE),ble1m0s1sbredr1)
# CONFIG_BT_BREDR := 1
# CONFIG_EM_SIZE=32
# CONFIG_BT_ALLROLES := 0
# CONFIG_BT_CENTRAL := 0
# CONFIG_BT_PERIPHERAL := 1
# CONFIG_BT_BROADCASTER := 1
# CONFIG_BT_OBSERVER := 1
# CONFIG_DISABLE_BLE_CONTROLLER_TEST_MODE := 1
# CONFIG_BT_CONN := 1
# CONFIG_BLE_TX_BUFF_DATA := 2
# CONFIG_BLE_ACT_MAX := 5
# CONFIG_ADV_EXTENSION := 0
# CONFIG_CIS := 0
# CONFIG_BIS := 0
# CONFIG_CTE := 0
# CONFIG_LE_PWR_CTRL := 0
# endif
# endif
    elseif("${PRIV_CONFIG_GEN_BLE}" STREQUAL "ble1m0s1sbredr1")
		set(CONFIG_BT_BREDR 1)
		set(CONFIG_EM_SIZE 32)
		set(CONFIG_BT_ALLROLES 0)
		set(CONFIG_BT_CENTRAL 0)
		set(CONFIG_BT_PERIPHERAL 1)
		set(CONFIG_BT_BROADCASTER 1)
		set(CONFIG_BT_OBSERVER 1)
		set(CONFIG_DISABLE_BLE_CONTROLLER_TEST_MODE 1)
		set(CONFIG_BT_CONN 1)
		set(CONFIG_BLE_TX_BUFF_DATA 2)
		set(CONFIG_BLE_ACT_MAX 5)
		set(CONFIG_ADV_EXTENSION 0)
		set(CONFIG_CIS 0)
		set(CONFIG_BIS 0)
		set(CONFIG_CTE 0)
		set(CONFIG_LE_PWR_CTRL 0)
    endif()
endif()

# ifndef CONFIG_FREERTOS_DISABLE
# CFLAGS   += -DCFG_FREERTOS
# endif
if(NOT DEFINED CONFIG_FREERTOS_DISABLE)
	sdk_add_compile_definitions(-DCFG_FREERTOS)
endif()

# CFLAGS   += -DARCH_RISCV

# ifeq ($(CONFIG_CHIP_NAME),BL602)
# CFLAGS   += -DBL602
# CFLAGS   += -DCONFIG_SET_TX_PWR
# endif
if("${CHIP}" STREQUAL "bl602")
	sdk_add_compile_definitions(CONFIG_SET_TX_PWR)
endif()

# ifeq ($(CONFIG_CHIP_NAME),BL702)
# CFLAGS   += -DBL702
# endif

# ifeq ($(CONFIG_CHIP_NAME),BL606P)
# CFLAGS   += -DBL606P
# CONFIG_BT_RESET=0
# endif
if("${CHIP}" STREQUAL "bl606p")
	set(CONFIG_BT_RESET, 0)
endif()

# ifeq ($(CONFIG_CHIP_NAME),BL808)
# CFLAGS   += -DBL808
# CONFIG_BT_RESET=0
# endif
if("${CHIP}" STREQUAL "bl808")
	set(CONFIG_BT_RESET, 0)
endif()

# ifeq ($(CONFIG_CHIP_NAME),BL616)
# CFLAGS   += -DBL616
# CONFIG_BT_RESET=0
# endif
if("${CHIP}" STREQUAL "bl616")
	set(CONFIG_BT_RESET, 0)
endif()

# ifeq ($(CONFIG_CHIP_NAME),BL808)
# CFLAGS   += -DBL808
# CONFIG_BT_RESET=0
# endif

# ifeq ($(CONFIG_CHIP_NAME),BL702L)
# CFLAGS   += -DBL702L
# endif

# ifeq ($(CONFIG_DBG_RUN_ON_FPGA), 1)
# CFLAGS   += -DCFG_DBG_RUN_ON_FPGA
# endif
sdk_add_compile_definitions_ifdef(CONFIG_DBG_RUN_ON_FPGA -DCFG_DBG_RUN_ON_FPGA)

# ifeq ($(CONFIG_BUILD_ROM_CODE),1)
# CFLAGS += -DBUILD_ROM_CODE
# endif
sdk_add_compile_definitions_ifdef(CONFIG_BUILD_ROM_CODE -DBUILD_ROM_CODE)

# CFLAGS   += -DCFG_BLE_ENABLE
# CPPFLAGS += -DCFG_BLE_ENABLE
# 
# CFLAGS   += -DBFLB_BLE
# CFLAGS   += -DCFG_BLE
sdk_add_compile_definitions(-DCFG_BLE_ENABLE)
sdk_add_compile_definitions(-DBFLB_BLE)
sdk_add_compile_definitions(-DCFG_BLE)
# CONFIG_BT_BREDR?=0
# ifeq ($(CONFIG_BT_BREDR),0)
# CONFIG_BT=0
# else
# CONFIG_BT=1
# CONFIG_BT_A2DP?=1
# CONFIG_BT_AVRCP?=1
# CONFIG_BT_HFP?=1
# ifeq ($(CONFIG_BT_A2DP),1)
# CFLAGS += -DCONFIG_BT_A2DP
# endif
# ifeq ($(CONFIG_BT_AVRCP),1)
# CFLAGS += -DCONFIG_BT_AVRCP
# endif
# ifeq ($(CONFIG_BT_HFP),1)
# CFLAGS += -DCONFIG_BT_HFP
# endif
# CFLAGS += -DCONFIG_BT_BREDR
# CFLAGS += -DCONFIG_MAX_SCO=2
# CFLAGS += -DSBC_DEC_INCLUDED
# CFLAGS += -DSBC_ENC_INCLUDED
# CFLAGS += -DCONFIG_BT_L2CAP_DYNAMIC_CHANNEL
# endif
if(NOT CONFIG_BT_BREDR)
	set(CONFIG_BT 0)
else()
	set(CONFIG_BT 1)
	set(CONFIG_BT_A2DP 1)
	set(CONFIG_BT_AVRCP 1)
	set(CONFIG_BT_HFP 1)
	sdk_add_compile_definitions_ifdef(CONFIG_BT_A2DP -DCONFIG_BT_A2DP)
	sdk_add_compile_definitions_ifdef(CONFIG_BT_AVRCP -DCONFIG_BT_AVRCP)
	sdk_add_compile_definitions_ifdef(CONFIG_BT_HFP -DCONFIG_BT_HFP)
	sdk_add_compile_definitions(
		-DCONFIG_BT_BREDR
		-DCONFIG_MAX_SCO=2
		-DSBC_DEC_INCLUDED
		-DSBC_ENC_INCLUDED
		-DCONFIG_BT_L2CAP_DYNAMIC_CHANNEL
	)
endif()

# ifeq ($(CONFIG_BT_TL),1)
# CFLAGS += -DCONFIG_BT_TL
# CONFIG_BLE_HOST_DISABLE:=1
# endif
if(CONFIG_BT_TL)
	sdk_add_compile_definitions(-DCONFIG_BT_TL)
	set(CONFIG_BLE_HOST_DISABLE 1)
endif()

# ifeq ($(CONFIG_BL_MCU_SDK),1)
# CFLAGS += -DBL_MCU_SDK
# endif
# sdk_add_private_compile_definitions_ifdef(CONFIG_BL_MCU_SDK -DBL_MCU_SDK)

# ifeq ($(CONFIG_EM_16K),1)
# CFLAGS += -DCONFIG_EM_16K
# endif
sdk_ifndef(CONFIG_EM_16K 0)
sdk_add_private_compile_definitions_ifdef(CONFIG_EM_16K -DCONFIG_EM_16K)

# ifeq ($(CONFIG_BT_MFG),1)
# CFLAGS += -DCONFIG_BT_MFG
# ifeq ($(CONFIG_BT_MFG_HCI_CMD),1)
# CFLAGS   += -DCONFIG_BT_MFG_HCI_CMD
# endif
# CONFIG_BT := 1
# CONFIG_SCO_ESCO := 0
# CONFIG_PCA := 0
# CONFIG_RF_EXTRC := 0
# CONFIG_CSB := 0
# CONFIG_SNIFF := 0
# CONFIG_RSWITCH := 0
# CONFIG_SEC_CONN := 0
# CONFIG_ADV_EXTENSION := 0
# CONFIG_CIS := 0
# CONFIG_BIS := 0
# CONFIG_LE_PWR_CTRL ?= 0
# endif

if(CONFIG_BT_MFG)
	sdk_add_compile_definitions(-DCONFIG_BT_MFG)
	sdk_add_private_compile_definitions_ifdef(CONFIG_BT_MFG_HCI_CMD -DCONFIG_BT_MFG_HCI_CMD)
	set(CONFIG_BT 1)
	set(CONFIG_SCO_ESCO 0)
	set(CONFIG_PCA 0)
	set(CONFIG_RF_EXTRC 0)
	set(CONFIG_CSB 0)
	set(CONFIG_SNIFF 0)
	set(CONFIG_RSWITCH 0)
	set(CONFIG_SEC_CONN 0)
	set(CONFIG_ADV_EXTENSION 0)
	set(CONFIG_CIS 0)
	set(CONFIG_BIS 0)
	set(CONFIG_LE_PWR_CTRL 0)
endif()

# CONFIG_BT ?= 1
# CONFIG_SCO_ESCO ?= 1
# CONFIG_PCA ?= 1
# CONFIG_RF_EXTRC ?= 1
# CONFIG_CSB ?= 1
# CONFIG_SNIFF ?= 1
# CONFIG_RSWITCH ?= 1
# CONFIG_TEST_MODE ?= 1
# CONFIG_BT_HCI_TEST_MODE ?= 1
# CONFIG_SEC_CONN ?= 1
# CONFIG_BT_DIRECT_TEST_MODE ?= 1
# CONFIG_BLE ?= 1
# CONFIG_CIS ?= 1
# CONFIG_ADV_EXTENSION ?= 1
# CONFIG_BIS ?= 1
# CONFIG_LONG_RANG ?= 1
# CONFIG_LE_PWR_CTRL ?= 1
# CONFIG_CTE ?= 1
# CONFIG_PHY_UPDATE ?= 1
# CONFIG_CLK_ACC ?= 1
# CONFIG_LE_PING ?= 1
# CONFIG_BLE_ACT_MAX ?= 5
sdk_ifndef(CONFIG_BT 1)
sdk_ifndef(CONFIG_SCO_ESCO 1)
sdk_ifndef(CONFIG_PCA 1)
sdk_ifndef(CONFIG_RF_EXTRC 1)
sdk_ifndef(CONFIG_CSB 1)
sdk_ifndef(CONFIG_SNIFF 1)
sdk_ifndef(CONFIG_RSWITCH 1)
sdk_ifndef(CONFIG_TEST_MODE 1)
sdk_ifndef(CONFIG_BT_HCI_TEST_MODE 1)
sdk_ifndef(CONFIG_SEC_CONN 1)
sdk_ifndef(CONFIG_BT_DIRECT_TEST_MODE 1)
sdk_ifndef(CONFIG_BLE 1)
sdk_ifndef(CONFIG_CIS 1)
sdk_ifndef(CONFIG_ADV_EXTENSION 1)
sdk_ifndef(CONFIG_BIS 1)
sdk_ifndef(CONFIG_LONG_RANG 1)
sdk_ifndef(CONFIG_LE_PWR_CTRL 1)
sdk_ifndef(CONFIG_CTE 1)
sdk_ifndef(CONFIG_PHY_UPDATE 1)
sdk_ifndef(CONFIG_LE_PING 1)
sdk_ifndef(CONFIG_CLK_ACC 1)
sdk_ifndef(CONFIG_BLE_ACT_MAX 5)

# ADD
sdk_ifndef(CONFIG_HW_SEC_ENG_DISABLE 0)

# CONFIG_BT_CONN?=2
# CFLAGS += -DCFG_CON=$(CONFIG_BT_CONN)
# CONFIG_BLE_TX_BUFF_DATA?=$(CONFIG_BT_CONN)
# CFLAGS += -DCFG_BLE_TX_BUFF_DATA=$(CONFIG_BLE_TX_BUFF_DATA)
# CONFIG_BT_ALLROLES?=1
# CONFIG_BT_CENTRAL?=1
# CONFIG_BT_OBSERVER?=1
# CONFIG_BT_PERIPHERAL?=1
# CONFIG_BT_BROADCASTER?=1
# CONFIG_BT_SETTINGS?=0
# CONFIG_BLE_TP_SERVER?=0
# CONFIG_BLE_MULTI_ADV?=0
# CONFIG_BLE_RECONNECT_TEST?=0
# CONFIG_BT_STACK_CLI?=1
# CONFIG_BLE_STACK_DBG_PRINT?=1
# CONFIG_BT_STACK_PTS?=0
# CONFIG_BLE_TP_TEST?=0
# CONFIG_BT_GEN_RANDOM_BY_SW?=0 #If BLE host generate random value by software
# CONFIG_DISABLE_BT_SMP?=0
# CONFIG_DISABLE_BT_HOST_PRIVACY?=1
# CONFIG_BT_L2CAP_DYNAMIC_CHANNEL?=0
# CONFIG_BT_GATT_CLIENT?=1
# CONFIG_BT_RESET?=1
# CONFIG_BT_MESH?=0
# CONFIG_BT_MESH_MODEL?=0

sdk_ifndef(CONFIG_BT_CONN 2)
sdk_add_compile_definitions(-DCFG_CON=${CONFIG_BT_CONN})
sdk_ifndef(CONFIG_BLE_TX_BUFF_DATA ${CONFIG_BT_CONN})
sdk_add_compile_definitions(-DCFG_BLE_TX_BUFF_DATA=${CONFIG_BLE_TX_BUFF_DATA})
sdk_ifndef(CONFIG_BT_ALLROLES 1)
sdk_ifndef(CONFIG_BT_CENTRAL 1)
sdk_ifndef(CONFIG_BT_OBSERVER 1)
sdk_ifndef(CONFIG_BT_PERIPHERAL 1)
sdk_ifndef(CONFIG_BT_BROADCASTER 1)
sdk_ifndef(CONFIG_BT_SETTINGS 0)
sdk_ifndef(CONFIG_BLE_TP_SERVER 0)
sdk_ifndef(CONFIG_BLE_MULTI_ADV 0)
sdk_ifndef(CONFIG_BLE_RECONNECT_TEST 0)
sdk_ifndef(CONFIG_BT_STACK_CLI 0)
sdk_ifndef(CONFIG_BLE_STACK_DBG_PRINT 1)
sdk_ifndef(CONFIG_BT_STACK_PTS 0)
sdk_ifndef(CONFIG_BLE_TP_TEST 1)
sdk_ifndef(CONFIG_BT_GEN_RANDOM_BY_SW 0)
sdk_ifndef(CONFIG_DISABLE_BT_SMP 0)
sdk_ifndef(CONFIG_DISABLE_BT_HOST_PRIVACY 1)
sdk_ifndef(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL 0)
sdk_ifndef(CONFIG_BT_GATT_CLIENT 1)
sdk_ifndef(CONFIG_BT_RESET 1)
sdk_ifndef(CONFIG_BT_MESH 0)
sdk_ifndef(CONFIG_BT_MESH_MODEL 0)

# ifeq ($(CONFIG_BT_MESH),1)
# CONFIG_BT_MESH_PB_ADV?=1
# CONFIG_BT_MESH_PB_GATT?=1
# CONFIG_BT_MESH_FRIEND?=1
# CONFIG_BT_MESH_LOW_POWER?=1
# CONFIG_BT_MESH_PROXY?=1
# CONFIG_BT_MESH_GATT_PROXY?=1
# CONFIG_BT_MESH_MOD_BIND_CB?=0
# CONFIG_BT_MESH_APPKEY_ADD_CB?=0
# CONFIG_BT_MESH_MOD_SUB_ADD_CB?=0
# ifeq ($(CONFIG_BT_MESH_MODEL), 1)
# CONFIG_BT_MESH_MODEL_GEN_SRV?=1
# CONFIG_BT_MESH_MODEL_GEN_CLI?=1
# CONFIG_BT_MESH_MODEL_LIGHT_SRV?=1
# CONFIG_BT_MESH_MODEL_LIGHT_CLI?=1
# else
# CONFIG_BT_MESH_MODEL_GEN_SRV?=1
# endif
# CONFIG_BT_MESH_PROVISIONER?=0
# ifeq ($(CONFIG_BT_MESH_PROVISIONER),1)
# CONFIG_BT_MESH_CDB?=1
# else
# CONFIG_BT_MESH_CDB?=0
# endif
# CONFIG_BT_MESH_SYNC?=0
# CONFIG_BT_MESH_NODE_SEND_CFGCLI_MSG?=0 # Config mesh normal node can send configure client message or not.
# endif
if(CONFIG_BT_MESH)
    sdk_ifndef(CONFIG_BT_MESH_PB_ADV 1)
    sdk_ifndef(CONFIG_BT_MESH_PB_GATT 1)
    sdk_ifndef(CONFIG_BT_MESH_FRIEND 1)
    sdk_ifndef(CONFIG_BT_MESH_LOW_POWER 1)
	sdk_ifndef(CONFIG_BT_MESH_PROXY 1)
    sdk_ifndef(CONFIG_BT_MESH_GATT_PROXY 1)
    sdk_ifndef(CONFIG_BT_MESH_MOD_BIND_CB 0)
    sdk_ifndef(CONFIG_BT_MESH_APPKEY_ADD_CB 0)
    sdk_ifndef(CONFIG_BT_MESH_MOD_SUB_ADD_CB 0)
    if(CONFIG_BT_MESH_MODEL)
		sdk_ifndef(CONFIG_BT_MESH_MODEL_GEN_SRV 1)
		sdk_ifndef(CONFIG_BT_MESH_MODEL_GEN_CLI 1)
		sdk_ifndef(CONFIG_BT_MESH_MODEL_LIGHT_SRV 1)
		sdk_ifndef(CONFIG_BT_MESH_MODEL_LIGHT_CLI 1)
    else()
    	sdk_ifndef(CONFIG_BT_MESH_MODEL_GEN_SRV 1)
    endif()
    sdk_ifndef(CONFIG_BT_MESH_PROVISIONER 0)
    if(CONFIG_BT_MESH_PROVISIONER)
    	sdk_ifndef(CONFIG_BT_MESH_CDB 1)
    else()
    	sdk_ifndef(CONFIG_BT_MESH_CDB 0)
    endif()
    sdk_ifndef(CONFIG_BT_MESH_SYNC 0)
    sdk_ifndef(CONFIG_BT_MESH_NODE_SEND_CFGCLI_MSG 0)
endif()

# ifeq ($(CONFIG_HW_SEC_ENG_DISABLE),1)
# CFLAGS += -DCONFIG_HW_SEC_ENG_DISABLE
# endif
sdk_add_private_compile_definitions_ifdef(CONFIG_HW_SEC_ENG_DISABLE -DCONFIG_HW_SEC_ENG_DISABLE)

##########################################
############## BLE STACK #################
##########################################

# ifeq ($(CONFIG_BT_ALLROLES),1)
# 
# CFLAGS += -DCONFIG_BT_ALLROLES
# CFLAGS += -DCONFIG_BT_CENTRAL
# CFLAGS += -DCONFIG_BT_OBSERVER
# CFLAGS += -DCONFIG_BT_PERIPHERAL
# CFLAGS += -DCONFIG_BT_BROADCASTER
# 
# else
# 
# ifeq ($(CONFIG_BT_CENTRAL),1)
# CFLAGS += -DCONFIG_BT_CENTRAL
# endif
# ifeq ($(CONFIG_BT_OBSERVER),1)
# CFLAGS += -DCONFIG_BT_OBSERVER
# endif
# ifeq ($(CONFIG_BT_PERIPHERAL),1)
# CFLAGS += -DCONFIG_BT_PERIPHERAL
# endif
# ifeq ($(CONFIG_BT_BROADCASTER),1)
# CFLAGS += -DCONFIG_BT_BROADCASTER
# endif
# 
# endif

if(CONFIG_BT_ALLROLES)
	sdk_add_compile_definitions(
		-DCONFIG_BT_ALLROLES
		-DCONFIG_BT_CENTRAL
		-DCONFIG_BT_OBSERVER
		-DCONFIG_BT_PERIPHERAL
		-DCONFIG_BT_BROADCASTER
	)
else()
	sdk_add_compile_definitions_ifdef(CONFIG_BT_CENTRAL -DCONFIG_BT_CENTRAL)
	sdk_add_compile_definitions_ifdef(CONFIG_BT_OBSERVER -DCONFIG_BT_OBSERVER)
	sdk_add_compile_definitions_ifdef(CONFIG_BT_PERIPHERAL -DCONFIG_BT_PERIPHERAL)
	sdk_add_compile_definitions_ifdef(CONFIG_BT_BROADCASTER -DCONFIG_BT_BROADCASTER)
endif()

# ifneq ($(CONFIG_DBG_RUN_ON_FPGA), 1)
# ifeq ($(CONFIG_BT_SETTINGS), 1)
# CFLAGS += -DCONFIG_BT_SETTINGS
# endif
# endif
if(NOT CONFIG_DBG_RUN_ON_FPGA)
	sdk_add_compile_definitions_ifdef(CONFIG_BT_SETTINGS -DCONFIG_BT_SETTINGS)
endif()

# ifeq ($(CONFIG_BLE_MFG),1)
# CFLAGS += -DCONFIG_BLE_MFG
# ifeq ($(CONFIG_BLE_MFG_HCI_CMD),1)
# CFLAGS   += -DCONFIG_BLE_MFG_HCI_CMD
# endif
# CONFIG_SEC_CONN := 0
# CONFIG_ADV_EXTENSION := 0
# CONFIG_CIS := 0
# CONFIG_BIS := 0
# CONFIG_LE_PWR_CTRL := 0
# CONFIG_DISABLE_CONTROLLER_BLE_PRIVACY := 1
# ifeq ($(CONFIG_CHIP_NAME),BL602)
# else ifeq ($(CONFIG_CHIP_NAME),BL702)
# else
# CONFIG_BT_ALLROLES := 0
# CONFIG_BT_CENTRAL := 0
# CONFIG_BT_OBSERVER := 0
# CONFIG_BT_PERIPHERAL := 0
# CONFIG_BT_BROADCASTER := 0
# endif
# endif
if(CONFIG_BLE_MFG)
	sdk_add_compile_definitions(-DCONFIG_BLE_MFG)
	sdk_add_compile_definitions_ifdef(CONFIG_BLE_MFG_HCI_CMD -DCONFIG_BLE_MFG_HCI_CMD)
	set(CONFIG_SEC_CONN 0)
	set(CONFIG_ADV_EXTENSION 0)
	set(CONFIG_CIS 0)
	set(CONFIG_BIS 0)
	set(CONFIG_LE_PWR_CTRL 0)
	set(CONFIG_DISABLE_CONTROLLER_BLE_PRIVACY 1)
	if("${CHIP}" STREQUAL "bl602")

	elseif(("${CHIP}" STREQUAL "bl702"))

	else()
		set(CONFIG_BT_ALLROLES 0)
		set(CONFIG_BT_CENTRAL 0)
		set(CONFIG_BT_OBSERVER 0)
		set(CONFIG_BT_PERIPHERAL 0)
		set(CONFIG_BT_BROADCASTER 0)
	endif()
endif()

# ifeq ($(CONFIG_BT_GEN_RANDOM_BY_SW),1)
# CFLAGS += -DCONFIG_BT_GEN_RANDOM_BY_SW
# endif
sdk_add_compile_definitions_ifdef(CONFIG_BT_GEN_RANDOM_BY_SW -DCONFIG_BT_GEN_RANDOM_BY_SW)

# ifeq ($(CONFIG_BLE_PDS),1)
# CFLAGS += -DCFG_BLE_PDS
# CFLAGS += -DCONFIG_HW_SEC_ENG_DISABLE
# endif
sdk_add_compile_definitions_ifdef(CONFIG_BLE_PDS -DCONFIG_BLE_PDS -DCONFIG_HW_SEC_ENG_DISABLE)

# ifneq ($(CONFIG_BT_CONN),0)
# CFLAGS   += 	-DCONFIG_BT_CONN
# endif
sdk_add_compile_definitions_ifdef(CONFIG_BT_CONN -DCONFIG_BT_CONN)

# CFLAGS   += -DCONFIG_BT_HCI_VS_EVT_USER \
#  			-DCONFIG_BT_ASSERT \
# endif
sdk_add_compile_definitions(-DCONFIG_BT_HCI_VS_EVT_USER -DCONFIG_BT_ASSERT)

# ifneq ($(CONFIG_SIMPLE_MASTER),1)
# CFLAGS   +=		-DCONFIG_BT_GATT_DIS_PNP \
#  			-DCONFIG_BT_GATT_DIS_SERIAL_NUMBER \
#  			-DCONFIG_BT_GATT_DIS_FW_REV \
#  			-DCONFIG_BT_GATT_DIS_HW_REV \
#  			-DCONFIG_BT_GATT_DIS_SW_REV \
#  			-DCONFIG_BT_GATT_DYNAMIC_DB \
#  			-DCONFIG_BT_GATT_SERVICE_CHANGED \
#  			-DCONFIG_BT_KEYS_OVERWRITE_OLDEST \
#  			-DCONFIG_BT_KEYS_SAVE_AGING_COUNTER_ON_PAIRING \
#  			-DCONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS \
#  			-DCONFIG_BT_BONDABLE 
# endif
if(NOT CONFIG_SIMPLE_MASTER)
sdk_add_compile_definitions(
	-DCONFIG_BT_GATT_DIS_PNP
	-DCONFIG_BT_GATT_DIS_SERIAL_NUMBER
	-DCONFIG_BT_GATT_DIS_FW_REV
	-DCONFIG_BT_GATT_DIS_HW_REV
	-DCONFIG_BT_GATT_DIS_SW_REV
	-DCONFIG_BT_GATT_DYNAMIC_DB
	-DCONFIG_BT_GATT_SERVICE_CHANGED
	-DCONFIG_BT_KEYS_OVERWRITE_OLDEST
	-DCONFIG_BT_KEYS_SAVE_AGING_COUNTER_ON_PAIRING
	-DCONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS
	-DCONFIG_BT_BONDABLE
)
endif()
# ifeq ($(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL),1)
# CFLAGS += -DCONFIG_BT_L2CAP_DYNAMIC_CHANNEL
# endif
sdk_add_compile_definitions_ifdef(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL -DCONFIG_BT_L2CAP_DYNAMIC_CHANNEL)

# ifeq ($(CONFIG_BT_GATT_CLIENT),1)
# CFLAGS += -DCONFIG_BT_GATT_CLIENT
# endif
sdk_add_compile_definitions_ifdef(CONFIG_BT_GATT_CLIENT -DCONFIG_BT_GATT_CLIENT)

# ifeq ($(CONFIG_BT_RESET),1)
# CFLAGS   += -DCFG_BT_RESET
# endif
sdk_add_compile_definitions_ifdef(CONFIG_BT_RESET -DCFG_BT_RESET)

# ifneq ($(CONFIG_DISABLE_BT_SMP), 1)
# CFLAGS += -DCONFIG_BT_SMP \
#  			-DCONFIG_BT_SIGNING
# endif
if(NOT CONFIG_DISABLE_BT_SMP)
	sdk_add_compile_definitions(-DCONFIG_BT_SMP -DCONFIG_BT_SIGNING)
endif()

# ifneq ($(CONFIG_DISABLE_BT_ECC), 1)
# CFLAGS += -DCONFIG_BT_ECC
# endif
if(NOT CONFIG_DISABLE_BT_ECC)
	sdk_add_compile_definitions(-DCONFIG_BT_ECC)
endif()

# ifneq ($(CONFIG_DBG_RUN_ON_FPGA), 1)
# CFLAGS += -DCONFIG_BT_SETTINGS_CCC_LAZY_LOADING \
#  			-DCONFIG_BT_SETTINGS_USE_PRINTK
# endif
if(NOT CONFIG_DBG_RUN_ON_FPGA)
	sdk_add_compile_definitions(-DCONFIG_BT_SETTINGS_CCC_LAZY_LOADING -DCONFIG_BT_SETTINGS_USE_PRINTK)
endif()

# ifeq ($(CONFIG_BLE_STACK_DBG_PRINT),1)
# CFLAGS += -DCFG_BLE_STACK_DBG_PRINT
# endif
sdk_add_compile_definitions_ifdef(CONFIG_BLE_STACK_DBG_PRINT -DCFG_BLE_STACK_DBG_PRINT)

# ifeq ($(CONFIG_BT_DEBUG_MONITOR),1)
# CFLAGS += -DCONFIG_BT_DEBUG_MONITOR
# endif
sdk_add_compile_definitions_ifdef(CONFIG_BT_DEBUG_MONITOR -DCONFIG_BT_DEBUG_MONITOR)

# ifeq ($(CONFIG_BLE_AT_CMD),1)
# CFLAGS += -DCONFIG_BLE_AT_CMD
# endif
sdk_add_compile_definitions_ifdef(CONFIG_BLE_AT_CMD -DCONFIG_BLE_AT_CMD)

#ifeq ($(CONFIG_BT_OAD_SERVER),1)
#CFLAGS += -DCONFIG_BT_OAD_SERVER
#endif
sdk_add_compile_definitions_ifdef(CONFIG_BT_OAD_SERVER -DCONFIG_BT_OAD_SERVER)

# ifeq ($(CONFIG_BT_OAD_CLIENT),1)
# CFLAGS += -DCONFIG_BT_OAD_CLIENT
# endif
sdk_add_compile_definitions_ifdef(CONFIG_BT_OAD_CLIENT -DCONFIG_BT_OAD_CLIENT)

# ifeq ($(CONFIG_HOGP_SERVER),1)
# CFLAGS += -DCONFIG_HOGP_SERVER
# endif
sdk_add_compile_definitions_ifdef(CONFIG_HOGP_SERVER -DCONFIG_HOGP_SERVER)

# ifeq ($(CONFIG_BT_BAS_SERVER),1)
# CFLAGS += -DCONFIG_BT_BAS_SERVER
# endif
sdk_add_compile_definitions_ifdef(CONFIG_BT_BAS_SERVER -DCONFIG_BT_BAS_SERVER)

# ifeq ($(CONFIG_BT_SPP_SERVER),1)
# CFLAGS += -DCONFIG_BT_SPP_SERVER
# endif
sdk_add_compile_definitions_ifdef(CONFIG_BT_SPP_SERVER -DCONFIG_BT_SPP_SERVER)

# ifeq ($(CONFIG_BT_SCPS_SERVER),1)
# CFLAGS += -DCONFIG_BT_SCPS_SERVER
# endif
sdk_add_compile_definitions_ifdef(CONFIG_BT_SCPS_SERVER -DCONFIG_BT_SCPS_SERVER)

# ifeq ($(CONFIG_BT_DIS_SERVER),1)
# CFLAGS += -DCONFIG_BT_DIS_SERVER
# endif
sdk_add_compile_definitions_ifdef(CONFIG_BT_DIS_SERVER -DCONFIG_BT_DIS_SERVER)

# ifeq ($(CONFIG_BT_REMOTE_CONTROL),1)
# CFLAGS += -DCONFIG_BT_REMOTE_CONTROL
# endif
sdk_add_compile_definitions_ifdef(CONFIG_BT_REMOTE_CONTROL -DCONFIG_BT_REMOTE_CONTROL)

# ifneq ($(CONFIG_DISABLE_BT_HOST_PRIVACY), 1)
# CFLAGS += -DCONFIG_BT_PRIVACY
# endif
if(NOT CONFIG_DISABLE_BT_HOST_PRIVACY)
	list(APPEND CFLAGS -DCONFIG_BT_PRIVACY)
	sdk_add_compile_definitions(-DCONFIG_BT_PRIVACY)
endif()

#ifneq ($(CONFIG_BT_REMOTE_CONTROL),1)
#ifneq ($(CONFIG_BT_MESH),1)
#CFLAGS += -DCONFIG_BT_PRIVACY
#endif
#endif

# ifeq ($(CONFIG_BLE_TP_SERVER),1)
# CFLAGS += -DCONFIG_BLE_TP_SERVER \
#           -DCONFIG_BT_GATT_DYNAMIC_DB
# ifeq ($(CONFIG_BLE_TP_TEST),1)
# CFLAGS += -DCONFIG_BLE_TP_TEST
# endif
# endif
if(CONFIG_BLE_TP_SERVER)
	sdk_add_compile_definitions(-DCONFIG_BLE_TP_SERVER)
	sdk_add_compile_definitions(-DCONFIG_BT_GATT_DYNAMIC_DB)
	sdk_add_compile_definitions_ifdef(CONFIG_BLE_TP_TEST -DCONFIG_BLE_TP_TEST)
endif()

# ifeq ($(CONFIG_BLE_MULTI_ADV),1)
# CFLAGS += -DCONFIG_BLE_MULTI_ADV
# endif
sdk_add_compile_definitions_ifdef(CONFIG_BLE_MULTI_ADV -DCONFIG_BLE_MULTI_ADV)

# ifeq ($(CONFIG_BLE_RECONNECT_TEST),1)
# CFLAGS += -DCONFIG_BLE_RECONNECT_TEST
# endif
sdk_add_compile_definitions_ifdef(CONFIG_BLE_RECONNECT_TEST -DCONFIG_BLE_RECONNECT_TEST)

# ifeq ($(CONFIG_BT_STACK_CLI),1)
# CFLAGS += -DCONFIG_BT_STACK_CLI
# endif
sdk_add_compile_definitions_ifdef(CONFIG_BT_STACK_CLI -DCONFIG_BT_STACK_CLI)

# ifeq ($(CONFIG_BT_STACK_PTS),1)
# CFLAGS += -DCONFIG_BT_STACK_PTS
# endif
sdk_add_compile_definitions_ifdef(CONFIG_BT_STACK_PTS -DCONFIG_BT_STACK_PTS)

# ifeq ($(PTS_TEST_CASE_INSUFFICIENT_KEY),1)
# CFLAGS += -DPTS_TEST_CASE_INSUFFICIENT_KEY
# endif
sdk_add_compile_definitions_ifdef(PTS_TEST_CASE_INSUFFICIENT_KEY -DPTS_TEST_CASE_INSUFFICIENT_KEY)
# ifeq ($(PTS_GAP_SLAVER_CONFIG_INDICATE_CHARC),1)
# CFLAGS += -DPTS_GAP_SLAVER_CONFIG_INDICATE_CHARC
# endif
sdk_add_compile_definitions_ifdef(PTS_GAP_SLAVER_CONFIG_INDICATE_CHARC -DPTS_GAP_SLAVER_CONFIG_INDICATE_CHARC)

# ifeq ($(CONFIG_ZIGBEE_PROV),1)
# CFLAGS += -DCONFIG_ZIGBEE_PROV
# endif
sdk_add_compile_definitions_ifdef(CONFIG_ZIGBEE_PROV -DCONFIG_ZIGBEE_PROV)

# ifeq ($(CONFIG_AUTO_PTS),1)
# CFLAGS += -DCONFIG_AUTO_PTS
# endif
sdk_add_compile_definitions_ifdef(CONFIG_AUTO_PTS -DCONFIG_AUTO_PTS)


##########################################
############## BLE MESH ##################
##########################################

# ifeq ($(CONFIG_BT_MESH),1)
# 
# ifeq ($(CONFIG_AUTO_PTS),1)
# CFLAGS += -DCONFIG_BT_MESH_IV_UPDATE_TEST
# endif
# CFLAGS += -DCONFIG_BT_MESH 
# ifeq ($(CONFIG_CHIP_NAME),BL602)
# CFLAGS += -DBFLB_CRYPT_HARDWARE
# else ifeq ($(CONFIG_CHIP_NAME),BL702)
# CFLAGS += -DBFLB_CRYPT_HARDWARE
# endif
# 
# CFLAGS += -DCONFIG_BT_MESH_PROV
# CFLAGS += -DCONFIG_BT_MESH_RELAY
# #CFLAGS += -DCONFIG_BT_SETTINGS
# ifeq ($(CONFIG_BT_MESH_PB_ADV),1)
# CFLAGS += -DCONFIG_BT_MESH_PB_ADV
# endif
# ifeq ($(CONFIG_BT_MESH_PB_GATT),1)
# CFLAGS += -DCONFIG_BT_MESH_PB_GATT
# endif
# ifeq ($(CONFIG_BT_MESH_FRIEND),1)
# CFLAGS += -DCONFIG_BT_MESH_FRIEND
# endif
# ifeq ($(CONFIG_BT_MESH_LOW_POWER),1)
# CFLAGS += -DCONFIG_BT_MESH_LOW_POWER
# endif
# ifeq ($(CONFIG_BT_MESH_PROXY),1)
# CFLAGS += -DCONFIG_BT_MESH_PROXY
# endif
# ifeq ($(CONFIG_BT_MESH_GATT_PROXY),1)
# CFLAGS += -DCONFIG_BT_MESH_GATT_PROXY
# endif
# ifeq ($(CONFIG_BT_MESH_MOD_BIND_CB),1)
# CFLAGS += -DCONFIG_BT_MESH_MOD_BIND_CB
# endif
# ifeq ($(CONFIG_BT_MESH_APPKEY_ADD_CB),1)
# CFLAGS += -DCONFIG_BT_MESH_APPKEY_ADD_CB
# endif
# ifeq ($(CONFIG_BT_MESH_MOD_SUB_ADD_CB),1)
# CFLAGS += -DCONFIG_BT_MESH_MOD_SUB_ADD_CB
# endif
# ifeq ($(CONFIG_BLE_STACK_DBG_PRINT),1)
# CFLAGS += -DCFG_BLE_STACK_DBG_PRINT
# endif
# ifeq ($(CONFIG_BT_MESH_SYNC),1)
# CFLAGS += -DCONFIG_BT_MESH_SYNC
# endif
# ifeq ($(CONFIG_BT_MESH_NODE_SEND_CFGCLI_MSG),1)
# CFLAGS += -DCONFIG_BT_MESH_NODE_SEND_CFGCLI_MSG
# endif
# ifeq ($(CONFIG_BT_MESH_CDB),1)
# CFLAGS += -DCONFIG_BT_MESH_CDB
# CFLAGS += -DCONFIG_BT_MESH_CDB_NODE_COUNT=64
# CFLAGS += -DCONFIG_BT_MESH_CDB_SUBNET_COUNT=2
# CFLAGS += -DCONFIG_BT_MESH_CDB_APP_KEY_COUNT=2
# endif 
# ifeq ($(CONFIG_BT_MESH_PROVISIONER),1)
# CFLAGS += -DCONFIG_BT_MESH_PROVISIONER
# CFLAGS += -DCONFIG_BT_MESH_CFG_CLI
# CFLAGS += -DCONFIG_BT_MESH_HEALTH_CLI
# endif
# ifeq ($(CONFIG_BT_MESH_MODEL),1)
# CFLAGS += -DCONFIG_BT_MESH_MODEL
# CFLAGS += -DCONFIG_BT_MESH_TEST
# ifeq ($(CONFIG_BT_MESH_MODEL_GEN_SRV),1)
# CFLAGS += -DCONFIG_BT_MESH_MODEL_GEN_SRV
# endif 
# ifeq ($(CONFIG_BT_MESH_MODEL_GEN_CLI),1)
# CFLAGS += -DCONFIG_BT_MESH_MODEL_GEN_CLI
# endif 
# ifeq ($(CONFIG_BT_MESH_MODEL_LIGHT_SRV),1)
# CFLAGS += -DCONFIG_BT_MESH_MODEL_LIGHT_SRV
# endif 
# ifeq ($(CONFIG_BT_MESH_MODEL_LIGHT_CLI),1)
# CFLAGS += -DCONFIG_BT_MESH_MODEL_LIGHT_CLI
# endif
# ifeq ($(CONFIG_BT_MESH_MODEL_VENDOR_CLI),1)
# CFLAGS += -DCONFIG_BT_MESH_MODEL_VENDOR_CLI
# endif
# else
# ifeq ($(CONFIG_BT_MESH_MODEL_GEN_SRV),1)
# CFLAGS += -DCONFIG_BT_MESH_MODEL_GEN_SRV
# endif 
# endif
# endif
if(CONFIG_BT_MESH)
	sdk_add_compile_definitions_ifdef(CONFIG_AUTO_PTS -DCONFIG_BT_MESH_IV_UPDATE_TEST)
	sdk_add_compile_definitions(-DCONFIG_BT_MESH -DCONFIG_BT_MESH_PROV -DCONFIG_BT_MESH_RELAY)
	if("${CHIP}" STREQUAL "bl602")
		sdk_add_compile_definitions(-DBFLB_CRYPT_HARDWARE)
	elseif("${CHIP}" STREQUAL "bl702")
		sdk_add_compile_definitions(-DBFLB_CRYPT_HARDWARE)
	endif()
	sdk_add_compile_definitions_ifdef(CONFIG_BT_MESH_PB_ADV -DCONFIG_BT_MESH_PB_ADV)
	sdk_add_compile_definitions_ifdef(CONFIG_BT_MESH_PB_GATT -DCONFIG_BT_MESH_PB_GATT)
	sdk_add_compile_definitions_ifdef(CONFIG_BT_MESH_FRIEND -DCONFIG_BT_MESH_FRIEND)
	sdk_add_compile_definitions_ifdef(CONFIG_BT_MESH_LOW_POWER -DCONFIG_BT_MESH_LOW_POWER)
	sdk_add_compile_definitions_ifdef(CONFIG_BT_MESH_PROXY -DCONFIG_BT_MESH_PROXY)
	sdk_add_compile_definitions_ifdef(CONFIG_BT_MESH_GATT_PROXY -DCONFIG_BT_MESH_GATT_PROXY)
	sdk_add_compile_definitions_ifdef(CONFIG_BT_MESH_MOD_BIND_CB -DCONFIG_BT_MESH_MOD_BIND_CB)
	sdk_add_compile_definitions_ifdef(CONFIG_BT_MESH_APPKEY_ADD_CB -DCONFIG_BT_MESH_APPKEY_ADD_CB)
	sdk_add_compile_definitions_ifdef(CONFIG_BT_MESH_MOD_SUB_ADD_CB -DCONFIG_BT_MESH_MOD_SUB_ADD_CB)
	sdk_add_compile_definitions_ifdef(CONFIG_BLE_STACK_DBG_PRINT -DCFG_BLE_STACK_DBG_PRINT)
	sdk_add_compile_definitions_ifdef(CONFIG_BT_MESH_SYNC -DCONFIG_BT_MESH_SYNC)
	sdk_add_compile_definitions_ifdef(CONFIG_BT_MESH_NODE_SEND_CFGCLI_MSG -DCONFIG_BT_MESH_NODE_SEND_CFGCLI_MSG)
	sdk_add_compile_definitions_ifdef(CONFIG_BT_MESH_CDB 
		-DCONFIG_BT_MESH_CDB
		-DCONFIG_BT_MESH_CDB_NODE_COUNT=64
		-DCONFIG_BT_MESH_CDB_SUBNET_COUNT=2
		-DCONFIG_BT_MESH_CDB_APP_KEY_COUNT=2
	)
	sdk_add_compile_definitions_ifdef(CONFIG_BT_MESH_PROVISIONER 
		-DCONFIG_BT_MESH_PROVISIONER
		-DCONFIG_BT_MESH_CFG_CLI
		-DCONFIG_BT_MESH_HEALTH_CLI
	)
    if(CONFIG_BT_MESH_MODEL)
		sdk_add_compile_definitions(-DCONFIG_BT_MESH_MODEL -DCONFIG_BT_MESH_TEST)
		sdk_add_compile_definitions_ifdef(CONFIG_BT_MESH_MODEL_GEN_SRV -DCONFIG_BT_MESH_MODEL_GEN_SRV)
		sdk_add_compile_definitions_ifdef(CONFIG_BT_MESH_MODEL_GEN_CLI -DCONFIG_BT_MESH_MODEL_GEN_CLI)
		sdk_add_compile_definitions_ifdef(CONFIG_BT_MESH_MODEL_LIGHT_SRV -DCONFIG_BT_MESH_MODEL_LIGHT_SRV)
		sdk_add_compile_definitions_ifdef(CONFIG_BT_MESH_MODEL_LIGHT_CLI -DCONFIG_BT_MESH_MODEL_LIGHT_CLI)
		sdk_add_compile_definitions_ifdef(CONFIG_BT_MESH_MODEL_VENDOR_CLI -DCONFIG_BT_MESH_MODEL_VENDOR_CLI)
    else()
		sdk_add_compile_definitions_ifdef(CONFIG_BT_MESH_MODEL_GEN_SRV -DCONFIG_BT_MESH_MODEL_GEN_SRV)
    endif()
endif()

# ifeq ($(CONFIG_USE_XTAL32K),1)
# CFLAGS += -DCFG_USE_XTAL32K
# endif
sdk_add_compile_definitions_ifdef(CONFIG_USE_XTAL32K -DCFG_USE_XTAL32K)

# CFLAGS   += -Wno-unused-const-variable  \
#             -Wno-unused-but-set-variable \
#             -Wno-format
## list(APPEND CFLAGS -Wno-unused-const-variable -Wno-unused-but-set-variable -Wno-format)